// TOWN SCRIPT
//    Town 8: Proving Grounds - Eighth Level

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

// flags:
// 8, 27 = balanced pre-sets
// 8, 28 = presets all gone
// 8, 29 = generate new monsters

begintownscript;

variables;

short i, j, x, y, choice;

body;

beginstate INIT_STATE;
	turn_off_training(1);
	set_crime_tolerance(1);

	// check monsters...
	run_scenario_script(22);
	if (get_flag(8, 29) > 0) {
		// generate some more...
		set_flag(8, 29, 0);
		print_str_color("Generating monsters...", 3);
		j = get_ran(1, 14, 24);
		i = 0;
		while (i < j) {
			run_scenario_script(34);
			if (get_flag(100, 0) > 0) {
				run_scenario_script(26);
				place_monster(get_flag(100, 1), get_flag(100, 2), get_flag(100, 0), 0);
			}
			i = i + 1;
		}
		run_scenario_script(43);
	}
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
break;

beginstate 10;
	reset_dialog();
	add_dialog_str(0, "There is an elevator here.", 0);
	add_dialog_str(1, "Use?", 0);
	add_dialog_choice(0, "No");
	add_dialog_choice(1, "Yes");
	choice = run_dialog(0);
	if (choice == 2) {
		block_entry(1);
		i = 0;
		while (i == 0) {
			get_text_response("Which level (A-F), E exits");
			check_text_response_match("A");
			if (got_text_match() > 0) {
				move_to_new_town(4, 24, 43);
				end();
			}
			check_text_response_match("B");
			if (got_text_match() > 0) {
				move_to_new_town(5, 23, 43);
				end();
			}
			check_text_response_match("C");
			if (got_text_match() > 0) {
				move_to_new_town(6, 24, 43);
				end();
			}
			check_text_response_match("D");
			if (got_text_match() > 0) {
				move_to_new_town(7, 24, 43);
				end();
			}
			check_text_response_match("E");
			if (got_text_match() > 0) {
				block_entry(0);
				// move_to_new_town(8, 24, 9);
				end();
			}
			check_text_response_match("F");
			if (got_text_match() > 0) {
				move_to_new_town(9, 24, 43);
				end();
			}
		}
	}
break;

beginstate 11;
	block_entry(1);
	reset_dialog();
	add_dialog_str(0, "There is a funny looking door here.", 0);
	add_dialog_str(1, "Go through it?", 0);
	add_dialog_choice(0, "Stay here");
	add_dialog_choice(1, "Go through");
	choice = run_dialog(0);
	if (choice == 2) {
		play_sound(-58);
		teleport_party(17, 44, 1);
		play_sound(59);
	}
break;

beginstate 12;
	teleport_party(32, 13, 1);
break;

beginstate 13;
	teleport_party(8, 11, 1);
break;

beginstate 14;
	teleport_party(12, 36, 1);
break;
